package com.eleven.mall.service.impl;

import com.eleven.mall.customexception.BusinessException;
import com.eleven.mall.mapper.RoleMapper;
import com.eleven.mall.pojo.ExType;
import com.eleven.mall.pojo.RoleOut;
import com.eleven.mall.pojo.entity.RoleExample;
import com.eleven.mall.pojo.entity.RoleWithBLOBs;
import com.eleven.mall.service.RoleService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: Rui_simple
 * @Date: 2022/10/26 10:27
 * @Description: RoleServiceImpl
 * @Version 1.0.0
 */
@AllArgsConstructor
@Service
public class RoleServiceImpl implements RoleService {
    RoleMapper roleMapper;

    /**
     * 获取角色列表
     * @return
     */
    @Override
    public List<RoleOut> getRoleList() {
        RoleExample roleExample = new RoleExample();
        List<RoleWithBLOBs> roleList = roleMapper.selectByExampleWithBLOBs(roleExample);
        if (roleList == null || roleList.isEmpty()){
            throw new BusinessException("roleList not found", ExType.BussRecordNotFound);
        }
        ArrayList<RoleOut> roleOutArrayList = new ArrayList<>();
        for (RoleWithBLOBs role : roleList) {
            RoleOut roleOut = new RoleOut();
            roleOut.setId(role.getRoleId().intValue());
            roleOut.setRoleDesc(role.getRoleDesc());
            roleOut.setRoleName(role.getRoleName());
            roleOutArrayList.add(roleOut);
        }
        return roleOutArrayList;
    }
}
